package com.fs.user.controller;

import com.fs.pandaFund.common.pojo.User;
import com.fs.pandaFund.common.util.PasswordUtils;
import com.fs.pandaFund.common.util.ResponseData;
import com.fs.pandaFund.common.util.ResponseDataUtil;
import com.fs.pandaFund.common.util.SmsUtil;
import com.fs.user.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * Author:HOU
 * date:2023/2/11  17:22
 * 案例:
 **/
@RestController
@RequestMapping("user")
public class EnrollController {
    @Autowired
    private UserServiceImpl userServiceImpl;

    @GetMapping("{phone}")
    public ResponseData code(@PathVariable("phone") String phone) throws Exception {
        userServiceImpl.ifExistPhone(phone);
        String s = SmsUtil.SMSVerification(phone);
        return ResponseDataUtil.buildOk(s);
    }
    @PostMapping("enroll")
    public ResponseData enroll (@RequestBody User user){
        user.setUpassword(PasswordUtils.generate(user.getUpassword()));
        userServiceImpl.enroll(user);
        return ResponseDataUtil.buildOk((Object) null);
    }
}
